package cn.edu.cqupt.cxcy.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.edu.cqupt.cxcy.dto.TeamImpl;
import cn.edu.cqupt.cxcy.model.Team;

/**
 * Servlet implementation class TeamIntroduce
 */
@WebServlet("/TeamIntroduce")
public class TeamIntroduce extends HttpServlet {
	private static final long serialVersionUID = 1L;
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setCharacterEncoding("text/html;charset=utf-8");
		String pjax_back = "$(function(){$(\"a.turn_pjax[href='team/tutor']\").trigger('click');});";
		if(request.getHeader("x-pjax") == null || request.getHeader("x-pjax").equals("null")) {
			request.setAttribute("pjax_back", pjax_back);
			request.getRequestDispatcher("Tteam.jsp").forward(request, response);
			return;
		} else if (request.getHeader("x-pjax").equals("true")) {
			HttpSession session = request.getSession();
			List<Object> list = (List<Object>)session.getAttribute("user");
			int teamId = (int)list.get(1);
			TeamImpl teamImpl = new TeamImpl();
            Team team = teamImpl.teamInfo(teamId);
            request.setAttribute("team", team);
			request.getRequestDispatcher("Ttutor.jsp").forward(request, response);
			return;
		}
	}

}
